<link rel="stylesheet" href="PLATFORM_CSS/wxMenu/wx_base.css">
<link rel="stylesheet" href="PLATFORM_CSS/wxMenu/tooltip218878.css">
<link rel="stylesheet" href="PLATFORM_CSS/wxMenu/wx_lib.css" />
<style>
.table tr td{text-align:center;vertical-align:middle;}
.table tr td:first-child{width:50%;}
.table tr td:last-child{width:20%;}
ul.mater{border:1px solid #e7e7eb;border-radius:5px;}
ul.mater li{padding:5px;border-bottom:1px solid #e7e7eb;}
ul.mater li:first-child{padding:13px 5px;}
ul.mater li:last-child{border-bottom:0px solid #e7e7eb;}
ul.mater li .btn_primary{display:inline-block;padding:3px;border-radius:3px;margin-right:10px;}
.dialog_ft .page{background:#f4f5f9;margin-top:10px;}
</style>
<div class="dialog_wrp media align_edge ui-draggable" style="display:none;width: 960px; margin-left: -480px; margin-top: -313.5px;" id="dialog_media">
	<div class="dialog">
		<div class="dialog_hd">
			<h3>选择素材</h3>
			<!--#0001#-->
			<a href="javascript:;" onclick="closeMaterial()"
				class="icon16_opr closed pop_closed">关闭</a>
			<!--%0001%-->
		</div>
		<div class="dialog_bd">
			<div class="dialog_media_container appmsg_media_dialog">
				<div class="sub_title_bar in_dialog">
					<div class="search_bar js-btn-media">
						<a class="btn btn_default" value="1" href="javascript:;" onclick="checkBtn(this)"> 文本 </a>
						<a class="btn btn_primary btn_default" value="2" href="javascript:;" onclick="checkBtn(this)"> 单图文 </a>
						<a class="btn btn_default" href="javascript:;" value="3" onclick="checkBtn(this)"> 多图文 </a>
					</div>
					<div class="appmsg_create tr">

						<!--
            <a class="" target="_blank" href="/cgi-bin/appmsg?t=media/appmsg_edit&action=edit&type=10&lang=zh_CN&token=254836048">
                <i class="icon_appmsg_small"></i><strong>新建单图文消息</strong>
            </a>
            -->
						<a class="btn btn_primary btn_add" target="_blank"
							href="PLATFORM_MAIN/Wchat/addMedia">
							<i class="icon14_common add_white"></i>新建图文消息
						</a>

					</div>
				</div>
				<div class="dialog_media_inner" style="overflow:auto;">
					<div class="table_wrp user_list">
						<table class="table" cellspacing="0">
							<tbody class="tbody" id="materia_data">
								
							</tbody>
							
						</table>
					</div>

					
				</div>
			</div>
		</div>

		<div class="dialog_ft">
			{include file="platform/page" /}
		</div>

	</div>
</div>

<div class="mask mask_metar" style="display: none;"></div>
<script>
$(function(){
	LoadingInfo(1);
});
function checkBtn(event){
	$(".js-btn-media").find('.btn').removeClass('btn_primary');
	$(event).addClass('btn_primary');
	LoadingInfo(1);
}
/**
 * 显示素材
 */
function showMaterial(){
	$("#dialog_media").fadeIn(500);
	$(".mask_metar").fadeIn(300);
}
// function LoadingInfo(pageIndex){
// 	var type = 2;
// 	onloadMaterial(pageIndex, type);
// }
/**
 * 加载 素材 数据
 */
function LoadingInfo(pageIndex){
// 	$(".js-btn-media").find('.btn').eq(type-1).addClass('btn_primary');
	var type = $(".js-btn-media .btn_primary").attr('value');
// 	var aa = $(".js-btn-media").find('.btn').eq(type).html();
// 	alert(aa);
	var search_text = '';
	$.ajax({
		type : "post",
		url : "PLATFORM_MAIN/Wchat/onloadMaterial",
		async : true,
		data : {
			"pageIndex" : pageIndex, "search_text" : search_text, "type" : type
		},
		success : function(data) {
// 			alert(JSON.stringify(data));
				$("#page_count").val(data["page_count"]);
				$("#pageNumber a").remove();
			var html = '';
			if(data['data'].length > 0){
				for(var i=0; i<data['data'].length; i++){
					if(data['data'][i]['type'] == 1){
						var type_name = '文本 ';
					}else if(data['data'][i]['type'] == 2){
						var type_name = '单图文 ';
					}else if(data['data'][i]['type'] == 3){
						var type_name = '多图文 ';
					}
					html += '<tr><td class="table_cell"><ul class="mater">';
					for(var l=0; l<data['data'][i]['item_list'].length; l++){
						var k = l+1;
						html += '<li><span class="btn_primary">'+ type_name + k+' </span><a href="#">'+data['data'][i]['item_list'][l]['title']+'</a></li>';
					}
					html += '</ul></td>';
					html += '<td>'+data['data'][i]['create_time']+'</td>';
					html += '<td class="table_cell user_opr tr"><a class="btn remark js_msgSenderRemark" onclick="selectedMaterial('+data['data'][i]['media_id']+')">选取</a></td>';
					html += '</tr>';
				}
			}else{
				html += '<tr>';
				html += '<td colspan="3" class="table_cell" style="text-align:center;">暂无素材</td>';
				html += '</tr>';
			}
			
			$("#materia_data tr").remove();
			$("#materia_data").append(html);
			var totalpage = $("#page_count").val();
			if (totalpage == 1) {
				changeClass("all");
			}
			var $html = pagenumShow(jumpNumber,totalpage,{$pageshow})
			$("#pageNumber").append($html);
		}
	});
}
/**
 * 选择 图文素材
 */
function selectedMaterial(media_id){
	getMaterial(media_id);
	closeMaterial();
}
/**
 *  取消  关闭
 */
function closeMaterial(){
	$("#dialog_media").fadeOut(300);
	$(".mask_metar").fadeOut();
}
</script>